<%@page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
String basePath = request.getContextPath();
%>
<% 
	String i="1"; 
%> 

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
	    <script language="javascript" type="text/javascript" 
			src="<%=basePath%>/js/validatorTool.js"></script>
		<script language="javascript" type="text/javascript"
			src="<%=basePath%>/js/utilTool.js"></script>
		<script language="javascript" type="text/javascript" src="<%=basePath%>/js/jquery-1.4.4.js"></script>
		<script language="javascript" type="text/javascript" src="<%=basePath%>/js/jquery.form.js"></script>
		<script language="javascript" type="text/javascript" src="<%=basePath%>/js/common.js"></script>
		<script language="javascript" type="text/javascript" src="<%=basePath%>/js/caltimer.js"></script>
	    
	    <script language="javascript" type="text/javascript"> 
	 		var currentView = 0;
	 	  		
    		function viewhistory(pk, k)
    		{   			
    			if (currentView > 0)
                	closeview(currentView);
                
                //ajax提交ctQueryForm	
                document.getElementById("qrySrcHpk").setAttribute("value", pk);
               
                document.getElementById("k").setAttribute("value", k);
                document.ctQueryForm.action = "<%=basePath%>/contractprice/ctreptlist/viewhistory";
                var options2 = {
					beforeSubmit : showRequest2, 
					success : showResponse2
				};
				$('#ctQueryForm').ajaxSubmit(options2);
				
                //切换"查看历史/收起历史"的显示
                if(currentView != k){
					var txtaa = document.getElementById("viewtext" + k);
					eval(txtaa);
					var frm = document.getElementById("viewform" + k);
					eval(frm);
	           		frm.style.display = "";
	            	//txtaa.innerText = "收起变更";
	           		txtaa.className = "viewhis3";
	            	currentView = k;	
		    	}else{
		    		currentView = 0;
		    	} 		    	
        	}
    		    		  
    		function showRequest2(formData, jqForm, options) {
			
			}
			function showResponse2(responseText, statusText, xhr, $form){
				var k=1;	       		    		    	
				if(responseText !='NULL')
	            {  
					for(var j = 0; j < eval("("+responseText+")").length; j++){
			    		var obj = eval("("+responseText+")")[j];
			    		k = obj.k; 
			    	}	
	                addRowsGyx(responseText, k);                                             
	            } 	
			}
    		    	
	    	function addRowsGyx(result,k){	    	

		    	var atable = document.getElementById("histable"+k);
		    	var newtable = eval(atable);	
		    	//显示前先清空上次显示结果
		    	for(var w=newtable.rows.length-1;  w>=0; w--){
		    		newtable.deleteRow(w);
		    	}
		    	
		    	//插入表头行	
			    newtable.insertRow(-1);	
			    newtable.rows[0].insertCell(-1).innerHTML="<th><input type='checkbox' id='selectAll"+ k + "' name='selectAll' onclick='selectAll(" + k + ")'>" 
			    				+ "<label class='linkstyle' onclick='exportDetail2ExlBatch(" + k + ")'>导出</label></th>";
			    newtable.rows[0].insertCell(-1).innerHTML="<th>变更申请单号</th>";
			    newtable.rows[0].insertCell(-1).innerHTML="<th>变更申请名称</th>"
			    newtable.rows[0].insertCell(-1).innerHTML="<th>计划生效日期</th>"
			    newtable.rows[0].insertCell(-1).innerHTML="<th>计划失效日期</th>"
			    newtable.rows[0].insertCell(-1).innerHTML="<th>单据状态</th>"
			    newtable.rows[0].insertCell(-1).innerHTML="<th>确认状态</th>"
			    newtable.rows[0].insertCell(-1).innerHTML="<th>操作</th>";
			   	
			   	//循环插入表体行	       		    		    	
		    	for(var j = 0; j < eval(result).length; j++){
		    		  
		    		var obj = eval(result)[j];
		    		newtable.insertRow(-1);		    		
		    		var rowIndex = newtable.rows.length-1;
		    		newtable.rows[rowIndex].insertCell(-1).innerHTML="<td><input type='checkbox' name='select"+ k +"' value='" + obj.pk_mdApp + "'/><input type='hidden' name='pk_mdApp' value='" + obj.pk_mdApp+ "'/></td>";
		    		newtable.rows[rowIndex].insertCell(-1).innerHTML="<td>" + obj.billno + "</td>";
		    		newtable.rows[rowIndex].insertCell(-1).innerHTML="<td><a href='<%=basePath%>/contractprice/ctreptlist/history/viewmd?pk_con_md_h=" + obj.pk_mdApp +"'  class='linkstyle'>" + obj.name + "</a></td>";
		    		newtable.rows[rowIndex].insertCell(-1).innerHTML="<td>" + obj.valDate + "</td>";
		    		newtable.rows[rowIndex].insertCell(-1).innerHTML="<td>" + obj.invalDate + "</td>";
		    		
		    		if(obj.billstatus=='0'){
			    		newtable.rows[rowIndex].insertCell(-1).innerHTML="<td> 审批未通过</td>";		    			
		    		}
		    		else if(obj.billstatus=='1'){
			    		newtable.rows[rowIndex].insertCell(-1).innerHTML="<td> 审批通过</td>";
		    		}else if(obj.billstatus=='2' ){
			    		newtable.rows[rowIndex].insertCell(-1).innerHTML="<td> 提交</td>";		    			
		    		}if(obj.billstatus=='3' ){
			    		newtable.rows[rowIndex].insertCell(-1).innerHTML="<td> 提交</td>";		    			
		    		}else if(obj.billstatus=='-1'){
			    		newtable.rows[rowIndex].insertCell(-1).innerHTML="<td> 未提交</td>";
		    		}
		    		
		    		if(obj.cfmstatus=='1'){
		    			newtable.rows[rowIndex].insertCell(-1).innerHTML="<td>待确认</td>";
		    		}else if(obj.cfmstatus=='2'){
		    			newtable.rows[rowIndex].insertCell(-1).innerHTML="<td>待确认</td>";
		    		}else if(obj.cfmstatus=='3'){
		    			newtable.rows[rowIndex].insertCell(-1).innerHTML="<td>接受</td>";
		    		}else if(obj.cfmstatus=='4'){
		    			newtable.rows[rowIndex].insertCell(-1).innerHTML="<td>拒绝</td>";
		    		}
		    		
		    		
		    		// 单据状态 和 确认状态共同决定了可以进行的操作 
		    		
		    		// 变更由甲方发起  
		    		if(obj.appSide=='1'){
		    			// 审批通过 && 状态为"确认中"，则显示操作为"确认"
		    		    if(obj.billstatus=='1' & obj.cfmstatus=='2'){
			    			newtable.rows[rowIndex].insertCell(-1).innerHTML="<td class='linkstyle'><a href='<%=basePath%>/contractprice/ctreptlist/history/confirm?pk_con_md_h=" + obj.pk_mdApp + "'>确认</a></td>";	
		    			}
		    			// 审批通过 && 状态为接受或聚居，则显示"新增"
		    			//else if(obj.billstatus=='1' & (obj.cfmstatus=='3' | obj.cfmstatus=='4')){
			    		//	newtable.rows[rowIndex].insertCell(-1).innerHTML="<td class='linkstyle'><a href='<%=basePath%>/contractprice/ctreptlist/viewhistory/addnew?pk_con_md_h=" + obj.pk_mdApp + "'>新建</a></td>";	
		    			//}		    			
		    		}
		    		// 变更由乙方发起
		    		else if(obj.appSide=='2'){
		    			// 如果 单据状态==自由，则显示操作为"编辑"
		    			if(obj.billstatus=='-1'){
				    		newtable.rows[rowIndex].insertCell(-1).innerHTML="<td class='linkstyle'><a href='<%=basePath%>/contractprice/ctreptlist/viewhistory/edit?pk_con_md_h=" + obj.pk_mdApp + "'>编辑</a></td>";	
		    			}
		    			// 如果  单据状态==提交  或 审批进行中， 则显示操作"新建"
		    			//else if(obj.billstatus=='2' | obj.billstatus=='3'){
				    	//	newtable.rows[rowIndex].insertCell(-1).innerHTML="<td class='linkstyle'><a href='<%=basePath%>/contractprice/ctreptlist/viewhistory/addnew?pk_con_md_h=" + obj.pk_mdApp + "'>新建</a></td>";	
		    			//}
		    			// 如果 单据状态==审批通过 或 审批未通过，则显示操作"新建"
		    			//else if(obj.billstatus=='0' | obj.billstatus=='1'){
				    	//	newtable.rows[rowIndex].insertCell(-1).innerHTML="<td class='linkstyle'><a href='<%=basePath%>/contractprice/ctreptlist/viewhistory/addnew?pk_con_md_h=" + obj.pk_mdApp + "'>新建</a></td>";	
		    			//}
		    		}	    				    		
		    	}
		}
		
		
        function closeview(k) {
            var txt = document.getElementById("viewtext" + k);
            eval(txt);
			var frm = document.getElementById("viewform" + k);
			eval(frm);
            var selEles = document.getElementsByName("select"+k);
            for(var j=0; j<selEles.length; j++){
            	selEles[j].checked = false;
            }
            frm.style.display = "none";
            //txt.innerText = "查看变更";
            txt.className = "viewhis2";         
        }
        
        function exportDetail2ExlBatch(k){
        	
        	var pksStr = "";
        	var checkedCount = 0;
        	
        	var selEles = document.getElementsByName("select"+k);
        	for(var i=0; i<selEles.length; i++){
        		if(selEles[i].checked == true){
        			checkedCount = checkedCount+1;
	        		pksStr = pksStr + selEles[i].value + "|";
        		}
        	}
        	document.getElementById("export_pks").value=pksStr;
        	
        	if(checkedCount==0){
        		alert("请选择待导出的变更申请!");
        	}else{
        		document.export_pk_form.action="<%=basePath%>/contractprice/exportdetail2ExlBatch";
        		document.export_pk_form.submit();
        	}
        }
        
        function selectAll(k){
        	var	ele = document.getElementById("selectAll" + k);
        	var eles = document.getElementsByName("select" + k);
        	if(ele.checked == true){
        		for(var i=0; i<eles.length; i++){
        			eles[i].checked=true;
        		}
        	}else{
        		for(var i=0; i<eles.length; i++){
        			eles[i].checked=false;
        		}
        	}
        }  
       
       //查询
        function qryCtData(){
        	document.ctQueryForm.action = "<%=basePath%>/contractprice/queryConRepo";
        	document.ctQueryForm.submit();
        }      				
	  </script>
	</head>
	
	<body class="fullbody" >	
            <div class="context">
                <div class="position">
                      <div class="tposi">
                                                                  当前位置：<a href="<%=request.getContextPath()%>/infopub/pubmain?menuid=1" class="linkstyle">首页</a>&nbsp;&gt;&gt;&nbsp;
                         <a href="javascript:changeMenu(3,'');" class="linkstyle" >我的订单\合同</a>
						 &nbsp;&gt;&gt;&nbsp;
						 <span class="curposition">合同协议报价维护</span>
					   </div>
					   <div class="help">
                  		<a href="javascript:void(null);" onclick="doHelp('<%=request.getContextPath()%>/help/html/HTXYBJWH.html');" class="linkstyle">帮助</a>
              		</div>
                    </div>
                <div class="margin8">
                </div>
                <div class="subpage_title">
                    <div class="title_index">
                        <img src="<%=basePath%>/images/common/dot03.gif" alt="" border="0" />&nbsp;合同协议报价维护</div>
                    <div class="rollback">
                         <a href="javascript:changeMenu(3,'');" class="linkstyle" >&lt;&lt;&nbsp;返回我的订单\合同</a>
                    </div>
                </div>
                <div class="margin10">
                </div>
                <div class="contract_price">
	                   <div class="subpage_search" >
                    	<form name="ctQueryForm" id="ctQueryForm" method="post">
                      		<table border="0" cellpadding="0" cellspacing="0" class="searchtable">
	                            <tr>
	                                <td valign="middle" class="w_1">合同协议报价名称：</td>
	                                <th valign="middle" class="w_2">
	                                    <input type="text" class="searchtext" name="qryCtName"  value="${QUERY_FORM.qryCtName}"  />
	                                    <!-- 冗余存合同协议报价主键 -->
	                                    <input type="hidden" name="qrySrcHpk" id="qrySrcHpk" value="" />  
	                                    <input type="hidden" name="k" id="k" value="" />  
	                                </th>
	                                <td valign="middle" class="w_1">变更申请名称：</td>
	                                <th valign="middle" class="w_2">
	                                   <input type="text" class="searchtext" name="qryCtMdName" id="qryCtMdName" value="${QUERY_FORM.qryCtMdName}"  />
	                                </th>
	                            </tr>
	                            <tr>
	                                <td valign="middle" class="w_1">计划生效日期：</td>
	                                <th valign="middle" class="w_2">
	                                     <input id="validDateBegin" name="validDateBegin" type="text" 
	                                     	type="text" onclick="return showCalendar('validDateBegin', 'y-mm-dd');"
												readonly="readonly" class="searchdate" value="${QUERY_FORM.validDateBegin}"/> 
										 &nbsp;至&nbsp;
										 <input id="validDateEnd" name="validDateEnd" type="text" 
	                                     	type="text" onclick="return showCalendar('validDateEnd', 'y-mm-dd');"
												readonly="readonly" class="searchdate" value="${QUERY_FORM.validDateEnd}"/>
	                                </th>
	                                <td valign="middle" class="w_1">计划失效日期：</td>
	                                <th valign="middle" class="w_2">
				                         <input id="inValidDateBegin" name="inValidDateBegin" type="text" 
	                                     	type="text" onclick="return showCalendar('inValidDateBegin', 'y-mm-dd');"
												readonly="readonly" class="searchdate" value="${QUERY_FORM.inValidDateBegin}"/>
										&nbsp;至&nbsp;
										<input id="inValidDateEnd" name="inValidDateEnd" type="text" 
	                                     	type="text" onclick="return showCalendar('inValidDateEnd', 'y-mm-dd');"
												readonly="readonly" class="searchdate" value="${QUERY_FORM.inValidDateEnd}"/>
	                                </th>
	                            </tr>
	                            <tr>
	                            	<td valign="middle" class="w_1">申请状态：</td>
	                                <td valign="middle" class="w_2">
		                                <select class="searchtext"
											name="qryBillStatus" id="qryBillStatus">
											<!-- 门户上的申请状态：-1:未提交；2:提交；1:审批通过； 0:审批未通过 -->
											<option value="100"  <c:if test="${100==QUERY_FORM.qryBillStatus}">selected</c:if>></option>
											<option value="-1" <c:if test="${1==QUERY_FORM.qryBillStatus}">selected</c:if>>未提交</option>
											<option value="2" <c:if test="${3==QUERY_FORM.qryBillStatus}">selected</c:if> <c:if test="${2==QUERY_FORM.qryBillStatus}">selected</c:if> >提交</option>
											<option value="1" <c:if test="${1==QUERY_FORM.qryBillStatus}">selected</c:if>>审批通过</option>
											<option value="0" <c:if test="${0==QUERY_FORM.qryBillStatus}">selected</c:if>>审批未通过</option>
										</select>
									</td>
	                                <td valign="middle" class="w_1">确认状态：</td>
	                                <td valign="middle" class="w_2">
		                                <select class="searchtext"
											name="qryCfmStatus" id="qryCfmStatus">
											<!-- 门户上的确认状态：1:待确认； 3:接受；4:拒绝 -->
											<option value="100" <c:if test="${100==QUERY_FORM.qryCfmStatus}">selected</c:if>>全部</option>
											<option value="1" <c:if test="${1==QUERY_FORM.qryCfmStatus}">selected</c:if> <c:if test="${2==QUERY_FORM.qryCfmStatus}">selected</c:if>>待确认</option>
											<option value="3" <c:if test="${3==QUERY_FORM.qryCfmStatus}">selected</c:if>>接受</option>
											<option value="4" <c:if test="${4==QUERY_FORM.qryCfmStatus}">selected</c:if>>拒绝</option>
										</select>
									</td>
	                            </tr>
	                           <tr><td colspan="4">&nbsp;</td></tr>
	                            <tr>
	                                <td valign="middle" colspan="4" align="center">
	                                    <input type="button" class="btnscs" value="查询" onclick="qryCtData()"/>&nbsp;&nbsp;
	                                    <input type="button" class="btnscs" value="取消" onclick="resetData()"/>
	                                </td>
	                            </tr>
	                        </table>
                        </form>
                    </div>
	                   
	                <div class="margin10">
                    </div>
                
                    <div class="margin20">
                    </div>
                       
                    <div class="itemlist">
                        <div>
							 <table class="tableCss" cellpadding="0" cellspacing="">
                                <tr  class="titleTr">
                                    <th width="203">
                                       	 合同
                                    </th>
                                    <th width="222" >
                                                                                                           合同协议报价
                                    </th>
                                    <th width="125" >
                                       	 发布时间
                                    </th>
                                    <th width="137" >
                                       	计划生效失效日期
                                    </th>
                                    <th width="55">
                                      	  新建变更
                                    </th>
                                    <th width="58" class="th1">
                                       	 查看变更
                                    </th>
                                </tr>  
                                       
								<c:if test="${CTREPO_LIST != null}">
									<c:forEach items="${CTREPO_LIST}" var="ctrep">
										 <%
											int x = Integer.parseInt(i);
										%> 
										<%
										 if(x%2==1){
										%>
										<tr class="contTr-old">
										<% } else {%>
										<tr class="contTr-even">
										<%} %>
											<td class="td1">
												编码：<c:out value="${ctrep.ct_no}"/><br/>
												名称：<c:out value="${ctrep.ct_name}" />
											</td>
											<td class="td1">
												编码：<c:out value="${ctrep.ctRepoNo}"/><br/>
												名称：<a href="<%=request.getContextPath()%>/contractprice/viewCtreptDetail?ctRepoPk=${ctrep.ctRepoPk}" class="linkstyle"><c:out value="${ctrep.ctRepoName}"/></a>
											</td>
											<td class="td1">
												<c:out value="${ctrep.issuedtime}"/>
											</td>
											<td class="td1">
												计划生效：<c:out value="${ctrep.supposeValidDate}"/><br/>
												计划失效：<c:out value="${ctrep.supposeInvalidDate}"/>
											</td>
											<td class="td1">
											 	<a href="<%=request.getContextPath()%>/contractprice/addnew?menuid=35&ctRepoPk=${ctrep.ctRepoPk}" class="linkstyle">新建变更</a>
											</td>
											<td class="td1" align="center" onclick="viewhistory('${ctrep.ctRepoPk}','<%=i%>')" >
												<div class="viewhis2" id="viewtext<%=i %>" >&nbsp;&nbsp;</div>
											</td>
										</tr>	
																				
										<tr align="left" class="detailview" style="display: none;" id="viewform<%=i%>" >
	                                    	<td colspan="8" style="white-space: nowrap;">
	                                    		<!-- <form id="formHis<%=i%>" name="formHis<%=i%>" action="" method="post">  -->
		                                        	<table border="0" cellpadding="2" cellspacing="0" class="detail_table" align="center" id="histable<%=i%>" >
		                                        	</table>
	                                        	<!-- </form> --> 
	                                        </td>
	                                    </tr>	
	                                   <%
											x++;
											i = String.valueOf(x);
										%> 						
									</c:forEach>
								</c:if>
                            </table>
                            
                            <form name="export_pk_form" id="export_pk_form" action="" method="post" >
                      			<input id="export_pks" name="export_pks" type="hidden" value="" />
                      		</form>
                            
                        </div>
                    </div> 
          			
                </div>
                               
                <div class="margin10">
                </div>
            </div>       
</body>


</html>
